﻿<UserControl x:Class="Papercut.Views.MessageListView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:ComponentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase"
             xmlns:cal="http://www.caliburnproject.org"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:Behaviors="clr-namespace:Papercut.Behaviors"
             mc:Ignorable="d"
             d:DesignHeight="400" d:DesignWidth="200"
             IsEnabled="{Binding Path=IsLoading,Converter={StaticResource InverseBooleanConverter}}">
    <i:Interaction.Behaviors>
        <Behaviors:InteractivityBlurOnDisabled BlurRadius="3" />
    </i:Interaction.Behaviors>
    <ListBox Name="MessagesList" Width="Auto" Height="Auto" SelectionMode="Extended" VirtualizingStackPanel.IsVirtualizing="false" 
             ScrollViewer.HorizontalScrollBarVisibility="Disabled"
             VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Padding="0" Margin="2"
             cal:Message.Attach="[Event KeyDown] = [Action MessageListKeyDown($eventArgs)]"
             ItemsSource="{Binding MessagesSorted}">
        <ListBox.ContextMenu>
            <ContextMenu>
                <MenuItem Header="Open Containing Folder..." IsEnabled="{Binding Path=HasSelectedMessage}"
                          cal:Message.Attach="OpenMessageFolder" />
            </ContextMenu>
        </ListBox.ContextMenu>
        <i:Interaction.Behaviors>
            <Behaviors:DragDropIFile />
        </i:Interaction.Behaviors>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid ToolTip="{Binding File}" Margin="2">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition
                            Width="{Binding Path=ViewportWidth, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ScrollViewer}}" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Column="0" Grid.Row="0" Text="{Binding Subject}" FontWeight="Bold"
                               TextTrimming="CharacterEllipsis"
                               Visibility="{Binding Subject, Converter={StaticResource CollapsedIfFalse}}" FontSize="14"/>
                    <TextBlock Grid.Column="0" Grid.Row="1" Text="{Binding DisplayText}"
                               TextTrimming="CharacterEllipsis" />
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
        <ListBox.ItemContainerStyle>
            <Style TargetType="{x:Type ListBoxItem}">
                <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
            </Style>
        </ListBox.ItemContainerStyle>
    </ListBox>

</UserControl>